package com.beordie.utils;

import java.sql.Time;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * @Classname DateFormatUtils
 * @Description 时间格式转换
 * @Date 2021/7/12 15:13
 * @Created 30500
 */
public class DateFormatUtils {
    private static SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm");
    private static SimpleDateFormat format_year = new SimpleDateFormat("yyyy-MM-dd");
    private static SimpleDateFormat format_hour = new SimpleDateFormat("HH:mm");
    /**
     * @description 解析时间
     * @author 30500
     * @date 2021/7/12 15:14
     * @type [java.util.Date]
     * @return java.lang.String
     */
    public static String getTimeString(Date date) {
        return format.format(date);
    }

    /**
     * @description 解析字符串
     * @author 30500
     * @date 2021/7/12 15:16
     * @type [java.lang.String]
     * @return java.util.Date
     */
    public static Date getTimeDate(String time) {
        Date result = null;
        try {
            result = format.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return result;
    }

    /**
     * @description 年月日
     * @author 30500
     * @date 2021/7/14 17:17
     * @type [java.util.Date]
     * @return java.lang.String
     */
    public static String getDateString(Date date) {
        return format_year.format(date);
    }

    /**
     * @description 时分
     * @author 30500
     * @date 2021/7/14 17:17
     * @type [java.sql.Time]
     * @return java.lang.String
     */
    public static String getTimeString(Time time) {
        return format_year.format(time);
    }

    public static Date getDate(String date) {
        Date result = null;
        try {
            result = format_year.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return result;
    }

    public static Date getTime(String time) {
        Date result = null;
        try {
            result = format_hour.parse(time);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return result;
    }
}
